package com.yanqu.road.server.cmd.relatives;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.relatives.RelativesProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_RELATIVES_ADD, desc = "成为亲家")
public class CrossRelativesAddCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        RelativesProto.CrossAddRelativesReqMsg reqMsg = RelativesProto.CrossAddRelativesReqMsg.parseFrom(packet.getBytes());
        UserBaseInfo userBaseInfo = CrossUserMgr.getUserBaseInfo(reqMsg.getRelativesId());
        if(userBaseInfo != null && userBaseInfo.getServerId() != reqMsg.getToServerId()){
            MessageHelper.sendPacket(userBaseInfo.getServerId(), reqMsg.getRelativesId(), YanQuMessageUtils.buildMessage(Protocol.S_RELATIVES_ADD_FROM_CROSS, reqMsg.toBuilder()));
        }else {
            MessageHelper.sendPacket(reqMsg.getToServerId(), reqMsg.getRelativesId(), YanQuMessageUtils.buildMessage(Protocol.S_RELATIVES_ADD_FROM_CROSS, reqMsg.toBuilder()));
        }
    }

    @Override
    public void sendData() {

    }
}
